package org.hxzon.rpggame.game;

import java.util.HashMap;
import java.util.Map;

import org.hxzon.hdyn.HFun;
import org.hxzon.hdyn.HGlobal;
import org.hxzon.util.db.Db;

public class Init {

    public static final HGlobal global = new HGlobal();

    public static void init() {
        Map<String, Db> dbs = new HashMap<String, Db>();
        global.add("dbs", dbs);
        global.add("addDb", new HFun(global) {
            @Override
            public Object invoke(Object thiz, Object... ps) {
                //Db
                Db db = (Db) ps[0];
                Map<String, Db> dbs = global.varToMap("dbs", Db.class);
                dbs.put(db.getName(), db);
                return null;
            }
        });
        global.add("getDb", new HFun(global) {
            @Override
            public Object invoke(Object thiz, Object... ps) {
                Map<String, Db> dbs = global.varToMap("dbs", Db.class);
                String name = (String) ps[0];
                return dbs.get(name);
            }
        });
    }
}
